<?php

namespace Common\Util\Baiduapi;


class Lexer{

    public function lexer_search($word){
        require_once('AipNlp.php');
        // 你的 APPID AK SK
        $APP_ID = '04a5b593f6f2474e8889a3661b989713';
        $API_KEY = '4a80c211b6f1424286967828f54b313d';
        $SECRET_KEY = 'd56ae43629354d6eaf05d788fbd1246f';
        $client = new \AipNlp($APP_ID, $API_KEY, $SECRET_KEY);
        $result = $client->lexer($word);

        $a=array();     //空白数组
        foreach($result['items'] as $v){
            if($v['byte_length']>=4){
                array_push($a,$v[item]);
            }
        }
        $aKeys = array_rand($a,5);   //随机取五个
        $aRand=array();  // 保存随机后的数组
        // 组合随机数组
        foreach($aKeys as $v){
            $aRand[$v]=$a[$v];
        }


        return $aRand;

    }


}

